#include <cstdio>

bool visit[ 32000 ];
int prime[ 4000 ], cnt;

void init( )
{
    int i, j;
    for ( i = 2; i <= 31999; i++ )
        if ( !visit[ i ] )
        {
            prime[ cnt++ ] = i;
            for ( j = i * 2; j <= 31999; j += i )
                visit[ j ] = true;
        }
}

bool check( int n )
{
    int i;
    for ( i = 0; prime[ i ] * prime[ i ] <= n && i < cnt; i++ )
        if ( n % prime[ i ] == 0 )
            break;
    if ( i == cnt || n % prime[ i ] != 0 )
        return true;
    while ( n % prime[ i ] == 0 )
        n /= prime[ i ];
    return n == 1;
}

int main( )
{
    int n;
    init( );
    while ( scanf("%d", &n) != EOF )
    {
        if ( n == 1 )
        {
            puts("0");
            continue;
        }
        if ( n == 2 )
        {
            puts("1");
            continue;
        }
        if ( n == 4 )
        {
            puts("3");
            continue;
        }
        if ( n & 1 )
        {
            if ( check( n ) )
                printf("%d\n", n - 1);
            else
                puts("1");
        }
        else
        {
            if ( n / 2 % 2 == 0 )
            {
                puts("1");
                continue;
            }
            if ( check( n / 2 ) )
                printf("%d\n", n - 1);
            else
                puts("1");
        }
    }
    return 0;
}
